<extend name="./app/Tpl/Public/template.html" />
<block name="content_body">
	<div class="pad-lr-10">
		<form name="form_search" id="form_search" action="{:U('index')}" method="post">
		    <table width="100%" cellspacing="0" class="search-form">
		        <tbody>
		            <tr>
			            <td>
				            <div class="explain-col">							
								<select name="cate_code" style="width:250px;" class="chosen_search">
									<option value="">全部分类列表</option>
	                				<volist name="cateTree" id="val_1">
								    	<option value="{$val_1.code}"  <if condition="$val_1['code'] eq $search['cate_code']">selected</if>>{$val_1.code}-{$val_1.title}</option>
										<volist name="val_1['children']" id="val_2">
											<option value="{$val_2.code}"  <if condition="$val_2['code'] eq $search['cate_code']">selected</if>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$val_2.code}{$val_2.title}</option>								
										</volist>
	                				</volist>
								</select>
								<input type="button"  name="form_search_btn_search"  value="查询" onclick="document.forms['form_search'].submit()"/>
								<input type="button"  name="form_search_btn_add"  value="新增商品" onclick='doAdd("{:U('showAdd')}")'/>
								<input type="button"  name="form_search_btn_add"  value="按分类编辑" onclick='doUpd("{:U('showUpd')}","cate")'/>
								<input type="button"  name="form_search_btn_removeCache"  value="刷新缓存商品" onclick="removeCache()"/>		
				        	</div>
			            </td>
		            </tr>
		        </tbody>
		    </table>
	    </form>
	    <form  name="form_list" id="form_list" action="{:U('index')}" method="post">
	    	<input type="hidden" name="auth_type" value="group">
		    <div class="table-list">		
			    <table width="100%" cellspacing="0">
			        <thead>
			            <tr>
			            	<th width="40" align="center">序号</th> 
			            	<th width="40" align="center">选中</th>  
			            	<th width="80" align="left">条形码</th>               
			                <th width="100" align="left">商品名称</th>
			                <th width="50" align="left">进货价</th>
			                <th width="50" align="left">零售价</th>
			                <th width="50" align="left">会员价</th>
			                <th width="80" align="left">规格/单位</th>
			      			<th width="40" align="left">热门</th>
			      			<th width="40" align="left">推荐</th>
			      			<th width="40" align="left">上架</th>
			      			<th width="80" align="left">排序</th>
			      			<th width="80" align="left">分类</th>
			      			<th align="left">操作</th>
			            </tr>
			        </thead>
			    	<tbody>
						<volist name="list" id='val'>
				        <tr>
				        	<td align="center">{$i}</td>
				            <td align="center"><input type="checkbox" value="{$val.id}" name="id[]"></td>
				            <td align="left">{$val.code}</td>
				            <td align="left"><span>{$val.name}</span></td>
				            <td align="left">{$val.price_buy}</td>
				            <td align="left">{$val.price_sale}</td>
				            <td align="left">{$val.price_vip}</td>
				            <td align="left">{$val.spec}/{$val.unit}</td>
				            <td align="left" onclick="isShow('{:U('isShow')}','{$val.id}','is_hot')" id="is_hot_{$val.id}"><img src="__ROOT__/statics/images/is_show_{$val.is_hot}.png" /></td>
				            <td align="left" onclick="isShow('{:U('isShow')}','{$val.id}','is_recommend')" id="is_recommend_{$val.id}"><img src="__ROOT__/statics/images/is_show_{$val.is_recommend}.png" /></td>
				            <td align="left" onclick="isShow('{:U('isShow')}','{$val.id}','is_show')" id="is_show_{$val.id}"><img src="__ROOT__/statics/images/is_show_{$val.is_show}.png" /></td>
				            <td align="left">
				            	<input type="text" class="input-text-c input-text" value="{$val.ordlist}" size="4" name="ordlist[{$val.id}]" id="ordlist_{$val.id}" onblur="ordlist('{:U('ordlist')}',{$val.id},'ordlist',this.value)"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
								<span id="ordlist_upd_{$val.id}" value="{$val.ordlist}"></span>
							</td>
							<td align="left">{$val.cate_code2}</td>		
				            <td align="left" class="btn">
				            		<a class="link_btn" href="{:U('showUpd',array('id'=>$val['id']))})" >编辑</a>
				            </td>
				        </tr>
				        </volist>
			    	</tbody>
			    </table>
	
			    <div class="btn">
					<input type="button"  name="form_list_btn_ckAll" class="ckSelect" ck_type="all" ck_name="id[]" value="全选" />
					<input type="button"  name="form_list_btn_ckNone" class="ckSelect" ck_type="none"  ck_name="id[]" value="全不选" />
					<input type="button"  name="form_list_btn_ckReverse" class="ckSelect" ck_type="reverse" ck_name="id[]" value="反选"/>
					<input type="button"  name="form_list_btn_ckDel" value="删除选中项" onclick="doDel('{:U('doDel')}')"/>
					<div id="pages">{$page}</div>
			    </div>
	    	</div>
	    </form>
	</div>
	<div id="dialog_content" title="弹出框"></div>
<script type="text/javascript">

$(function(){
	//展开&收缩
	$('.expandable').toggle(
		function(){
			$('.pid_'+$(this).attr('id')).hide();		
			$(this).attr('src',ROOT_PATH+'/statics/images/tv-expandable.gif');
		},
		function(){
			$('.pid_'+$(this).attr('id')).show();
			$(this).attr('src',ROOT_PATH+'/statics/images/tv-collapsable.gif');
		}
	);
	//打开编辑窗口
	$( "#dialog_content" ).dialog({
		autoOpen: false,
		width:500,
		height:400
	});
})

function doAdd(action_url){
	var cate_code = document.forms['form_search'].elements['cate_code'].value;
	var url = action_url+"?cate_code="+cate_code
	redirect(url);
}

function doUpd(action_url,type){
	var url = action_url
	if(type == 'cate'){
		var cate_code = document.forms['form_search'].elements['cate_code'].value;
		if(cate_code==''){
			alert('请选择分类');
			return;
		}
		url = url+"?cate_code="+cate_code;
	}
	redirect(url);
}

//删除操作
function doDel(action_url){
	if(confirm("确定删除选中项（如果选中项下有子菜单，会一同被删除）？")){
		$("#form_list").attr('action',action_url);
		$("#form_list").submit();
	}
	
}

//刷新菜单缓存文件
function removeCache(){
	$.get("{:U('removeCache')}", { }, function(jsondata){ 
		alert(jsondata);
	},'json'); 
}
</script>
</block>